package com.study.security.utils;

import com.study.common.BusinessException;
import com.study.security.domain.CurrentUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtils {

    private static Authentication getAuthentication() {
        return SecurityContextHolder.getContext().getAuthentication();
    }

    public static CurrentUser getCurrentUser() {
        try {
            return (CurrentUser) getAuthentication().getPrincipal();
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("获取登录用户失败");
        }
    }


}
